/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.shape;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;


/**
*A class representing a shape function for the T10 tetrahedral element.
*
*@author Lucas, Marcelo & Pitangueira, Roque
*@version 1.0
*@since November 2004
*/

public class Tetra10 extends Shape3D 
{
	private static final long serialVersionUID = 1L;

	/** Constructs a shape function for tetrahedral element T10 and sets its type to "Tetra10".*/
	public Tetra10() 
	{
		type = "Tetra10";
	}
	
//********************************************************************************
	
	/** Returns the IVector containing the values of shape function evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@return The IVector containing the values of shape function evalueted in provided points.
	*/
	public IVector getShapeFunction(double[] g) 
	{
		double a = g[0];
		double b = g[1];
		double c = g[2];
		
		IVector n = new IVector(10);
		
		double n0 = (((-1)*(1-a-b-c))*(1-2*(1-a-b-c)));
		double n1 = ((4*a)*(1-a-b-c));
		double n2 = ((-a)*(1-2*a));
		double n3 = (4*a*b);
		double n4 = ((-b)*(1-2*b));
		double n5 = ((4*b)*(1-a-b-c));
		double n6 = ((4*c)*(1-a-b-c));
		double n7 = (4*a*c);
		double n8 = (4*b*c);
		double n9 = ((-c)*(1-2*c));

		n.setElement(0,n0);
		n.setElement(1,n1);
		n.setElement(2,n2);
		n.setElement(3,n3);
		n.setElement(4,n4);
		n.setElement(5,n5);
		n.setElement(6,n6);
		n.setElement(7,n7);
		n.setElement(8,n8);
		n.setElement(9,n9);
		
		return (n);
	}
	
//********************************************************************************
	
	/** Returns the IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*@param g The vector containing the coordinates which the shape function will be evalueted.
	*@return The IMatrix containing the values of shape function derived in xi and eta evalueted in provided points.
	*/
	public IMatrix getDerivedShapeFunction(double[] g) 
	{
		double a = g[0];
		double b = g[1];
		double c = g[2];
		
		IMatrix dl = new IMatrix(3,10);
		
	//derivadas em relacao a xi (a = xi e b = eta e c = zeta)
		double dxi0 = (1-4*(1-a-b-c));
		double dxi1 = (4*((1-a-b-c)-a));
		double dxi2 = (-1+4*a);
		double dxi3 = (4*b);
		double dxi4 = (0);
		double dxi5 = (-4*b);
		double dxi6 = (-4*c);
		double dxi7 = (4*c);
		double dxi8 = (0);
		double dxi9 = (0);
	//derivadas em relacao a eta (a = xi e b = eta e c = zeta)
		double deta0 = (1-4*(1-a-b-c));
		double deta1 = (-4*a);
		double deta2 = (0);
		double deta3 = (4*a);
		double deta4 = (-1+4*b);
		double deta5 = (4*((1-a-b-c)-b));
		double deta6 = (-4*c);
		double deta7 = (0);
		double deta8 = (4*c);
		double deta9 = (0);
	//derivadas em relacao a zeta (a = xi e b = eta e c = zeta)
		double dzeta0 = (1-4*(1-a-b-c));
		double dzeta1 = (-4*a);
		double dzeta2 = (0);
		double dzeta3 = (0);
		double dzeta4 = (0);
		double dzeta5 = (-4*b);
		double dzeta6 = (4*((1-a-b-c)-c));
		double dzeta7 = (4*a);
		double dzeta8 = (4*b);
		double dzeta9 = (-1+4*c);
		
	//derivadas em relacao a xi na linha 0 da IMatrix
		dl.setElement(0,0,dxi0);
		dl.setElement(0,1,dxi1);
		dl.setElement(0,2,dxi2);
		dl.setElement(0,3,dxi3);
		dl.setElement(0,4,dxi4);
		dl.setElement(0,5,dxi5);
		dl.setElement(0,6,dxi6);
		dl.setElement(0,7,dxi7);
		dl.setElement(0,8,dxi8);
		dl.setElement(0,9,dxi9);
	//derivadas em relacao a eta na linha 1 da IMatrix
		dl.setElement(1,0,deta0);
		dl.setElement(1,1,deta1);
		dl.setElement(1,2,deta2);
		dl.setElement(1,3,deta3);
		dl.setElement(1,4,deta4);
		dl.setElement(1,5,deta5);
		dl.setElement(1,6,deta6);
		dl.setElement(1,7,deta7);
		dl.setElement(1,8,deta8);
		dl.setElement(1,9,deta9);
	//derivadas em relacao a zeta na linha 2 da IMatrix
		dl.setElement(2,0,dzeta0);
		dl.setElement(2,1,dzeta1);
		dl.setElement(2,2,dzeta2);
		dl.setElement(2,3,dzeta3);
		dl.setElement(2,4,dzeta4);
		dl.setElement(2,5,dzeta5);
		dl.setElement(2,6,dzeta6);
		dl.setElement(2,7,dzeta7);
		dl.setElement(2,8,dzeta8);
		dl.setElement(2,9,dzeta9);
		
		return (dl);
	}
	
//********************************************************************************
	
	/** Return the IMatrix containing nodal coordinates of this shape in natural system.
	*@return natCoords The IMatrix with nodal coordinates of this shape in natural system.
	*/
	public IMatrix getNaturalNodalCoords()
	{
		IMatrix natCoords = new IMatrix(3,10);
		
	//coordenadas naturais de xi
		natCoords.setElement(0,0,1);
		natCoords.setElement(0,1,0.5);
		natCoords.setElement(0,2,0);
		natCoords.setElement(0,3,0);
		natCoords.setElement(0,4,0);
		natCoords.setElement(0,5,0.5);
		natCoords.setElement(0,6,0.5);
		natCoords.setElement(0,7,0);
		natCoords.setElement(0,8,0);
		natCoords.setElement(0,9,0);
	//coordenadas naturais de eta
		natCoords.setElement(1,0,0);
		natCoords.setElement(1,1,0.5);
		natCoords.setElement(1,2,1);
		natCoords.setElement(1,3,0.5);
		natCoords.setElement(1,4,0);
		natCoords.setElement(1,5,0);
		natCoords.setElement(1,6,0);
		natCoords.setElement(1,7,0.5);
		natCoords.setElement(1,8,0);
		natCoords.setElement(1,9,0);
	//coordenadas naturais de zeta
		natCoords.setElement(2,0,0);
		natCoords.setElement(2,1,0);
		natCoords.setElement(2,2,0);
		natCoords.setElement(2,3,0.5);
		natCoords.setElement(2,4,1);
		natCoords.setElement(2,5,0.5);
		natCoords.setElement(2,6,0);
		natCoords.setElement(2,7,0);
		natCoords.setElement(2,8,0.5);
		natCoords.setElement(2,9,0);
		
		return natCoords;
	}
	
//********************************************************************************

}

